package com.njegovanobradovic.core.facade;

import java.io.Serializable;
import java.util.UUID;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Version;

import org.apache.tapestry5.beaneditor.NonVisual;

@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public class BaseDO implements Serializable {
	
	private static final long serialVersionUID = 1685615540034161333L;
	private Long _id;
	private String _uuid = UUID.randomUUID().toString();
	
	@Version
	@Column(name = "BASEBEAN_VERSION")
	private int _version;
	
	public BaseDO() {
		super();
	}

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@NonVisual
	public Long get_id() {
		return _id;
	}
	
	public void set_id(Long id) {
		this._id = id;
	}

	public void set_id(Serializable id) {
		this.set_id((Long)id);
	}

	@Basic
	@NonVisual
	public String get_uuid() {
		return _uuid;
	}

	public void set_uuid(String _uuid) {
		this._uuid = _uuid;
	}
	
	@Override
	public int hashCode() {
        if (get_uuid() != null) {
            return get_uuid().hashCode();
        } else {
            return super.hashCode();
        }
    }
}
